package saves.objects;

import game.Units;
import images.ImageInfo;
import java.awt.Color;
import org.jbox2d.collision.shapes.PolygonShape;
import org.jbox2d.dynamics.BodyType;
import org.jbox2d.dynamics.FixtureDef;
import org.jbox2d.dynamics.World;

/**
 *
 * @author Luan
 */
public class CorpoImpl extends Corpo {
    private static final long serialVersionUID = 1L;
    
    private int w, h;
    private transient Color c;
    
    private CorpoImpl() { }
    
    public CorpoImpl(float x, float y, int w, int h, Color c, World world) {
        super(x, y, -1, BodyType.DYNAMIC, world);
        
        this.w = w;
        this.h = h;
        this.c = c;
        
        PolygonShape ps = new PolygonShape();
        ps.setAsBox(Units.getRealSize(w/2), Units.getRealSize(h/2));
        
        FixtureDef fd = new FixtureDef();
        fd.shape = ps;
        this.body.createFixture(fd);
        
        //todo testing
        this.body.setAngularVelocity(5);
    }
    
    @Override
    public int getPixelWidth() {
        return this.w;
    }
    
    @Override
    public int getPixelHeight() {
        return this.h;
    }
    
    @Override
    public void draw(int x, int y, int w, int h) {
        ImageInfo.rotate(this.getDrawingAngle(), x, y);
        ImageInfo.drawColorSquare(x - w/2, y - h/2, w, h, c);
        ImageInfo.rotate(-this.getDrawingAngle(), x, y);
    }
    
    @Override
    public void draw(int x, int y) {
        ImageInfo.rotate(this.getDrawingAngle(), x, y);
        draw(x - w/2, y - h/2, w, h); //w and h already in pixels
        ImageInfo.rotate(-this.getDrawingAngle(), x, y);
    }
}
